<?php

namespace App\Http\Controllers\Api\Train;

use App\Http\Controllers\Controller;
use App\Http\Resources\Train\Station\PassPointsResource;
use App\Trip\Train\Providers\Ctrip\TrainQuery;
use Carbon\Carbon;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request;

class TrainController extends Controller
{
    /**
     * @throws GuzzleException
     */
    public function pass_points(Request $request)
    {
        $query  = new TrainQuery();
        $points = $query->queryStationPoints($request->input('train_code', ''), $request->input('train_date', Carbon::now()->toDateString()));
        $request->offsetSet('points_count', collect($points)->count());
        $ret = [
            'points' => PassPointsResource::collection($points),
        ];
        return $this->success('', $ret);
    }
}
